package controller

import (
	"fmt"
	"github.com/gin-gonic/gin"
)

type ExceptionController struct{}

func (e ExceptionController) Defer(c *gin.Context) {
	defer fmt.Println(1)
	defer fmt.Println(2)
	defer fmt.Println(3)
	// 输出：3
	// 输出：2
	// 输出：1
}

func (e ExceptionController) Panic(c *gin.Context) {
	defer func() {
		if err := recover(); err != nil {
			fmt.Println("捕获异常：", err)
			// 输出：捕获异常： 11
		}
	}()

	panic("11")
}

func (e ExceptionController) Zero(c *gin.Context) {
	num1 := 1
	num2 := 0
	num3 := num1 / num2
	fmt.Println(num3)
}
